package com.ruoyi.book.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.book.mapper.BookMapper;
import com.ruoyi.book.domain.Book;
import com.ruoyi.book.service.IBookService;

/**
 * 书本信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-02
 */
@Service
public class BookServiceImpl implements IBookService 
{
    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询书本信息
     * 
     * @param id 书本信息主键
     * @return 书本信息
     */
    @Override
    public Book selectBookById(Long id)
    {
        return bookMapper.selectBookById(id);
    }

    /**
     * 查询书本信息
     *
     * @param num 书本编号
     * @return 书本信息
     */
    @Override
    public Book selectBookByNum(String num) {
        return bookMapper.selectBookByNum(num);
    }

    /**
     * 通过书本编号得到拥有者信息
     *
     * @param num 书本编号
     * @return 拥有者信息
     */
    @Override
    public SysUser selectUserByBookNum(String num) {
        String createBy = bookMapper.selectBookByNum(num).getCreateBy();
        return userMapper.selectUserByUserName(createBy);
    }

    /**
     * 查询书本信息列表
     * 
     * @param book 书本信息
     * @return 书本信息
     */
    @Override
    public List<Book> selectBookList(Book book)
    {
        return bookMapper.selectBookList(book);
    }

    /**
     * 新增书本信息
     * 
     * @param book 书本信息
     * @return 结果
     */
    @Override
    public int insertBook(Book book)
    {
        book.setCreateBy(book.getCreateBy());
        book.setCreateTime(DateUtils.getNowDate());
        return bookMapper.insertBook(book);
    }

    /**
     * 修改书本信息
     * 
     * @param book 书本信息
     * @return 结果
     */
    @Override
    public int updateBook(Book book)
    {
        book.setUpdateTime(DateUtils.getNowDate());
        return bookMapper.updateBook(book);
    }

    /**
     * 批量删除书本信息
     * 
     * @param ids 需要删除的书本信息主键
     * @return 结果
     */
    @Override
    public int deleteBookByIds(Long[] ids)
    {
        return bookMapper.deleteBookByIds(ids);
    }

    /**
     * 删除书本信息信息
     * 
     * @param id 书本信息主键
     * @return 结果
     */
    @Override
    public int deleteBookById(Long id)
    {
        return bookMapper.deleteBookById(id);
    }

    /**
     * 判断书本编号是否唯一
     *
     * @param book 书本信息
     * @return  结果
     */
    @Override
    public boolean checkBookNumUnique(Book book) {
        Book book1 = bookMapper.checkBookNumUnique(book.getNum());
        return book1 != null;
    }
    /**
     * 查询可借阅书籍集合
     *
     * @param bookBorrow 借阅处理
     * @return 借阅处理集合
     */
    @Override
    public List<Book> selectShareBookList(Book bookBorrow) {
        return bookMapper.selectShareBookList(bookBorrow);
    }

    /**
     * 查询可借阅书籍
     *
     * @param id 书籍借阅主键
     * @return 书籍借阅
     */
    @Override
    public Book selectShareBookById(Long id) {
        return bookMapper.selectShareBookById(id);
    }
}
